package com.k8.common.factroy;

import com.k8.common.ioc.Injector;
import com.k8.common.ioc.injectorImpl.SafeObjectHolder;

import java.util.List;
import java.util.Map;

/**
 * 为抽象类提供的BeanInject工具
 * 不要修改传递进来的参数
 * 在injectBean里调用其他获取bean的方法即可
 * */
public interface BeanRegistry {
    /**
     *为了防止方法被重写修改map中的元素，所以用了一个Safe类进行持有真实变量，Safe类只有在injector包下才能操作
     */

    default  <T> T getBean(Injector injector, final Map<String, SafeObjectHolder> relyBeanMaps, Class<T> clazz, String name){
            return injector.getBean(relyBeanMaps,clazz,name);
    }
    default <T> T getBean(Injector injector, final Map<String, SafeObjectHolder> relyBeanMaps, Class<T> clazz){
            return injector.getBean(relyBeanMaps,clazz);
    }
    default <T> List<T> getAllBeans(Injector injector, final Map<String, SafeObjectHolder> relyBeanMaps, Class<T> clazz){
        return injector.getAllBeans(relyBeanMaps,clazz);
    }
    default <T> T getBeanOrRegistry(Injector injector,final Map<String,SafeObjectHolder> relyBeanMaps,Class<T> clazz ,String name){
            return injector.getBeanOrRegistry(relyBeanMaps,clazz,name);
    }
    default <T> T getBeanOrRegistry(Injector injector,final Map<String,SafeObjectHolder> relyBeanMaps,Class<T> clazz){
            return injector.getBeanOrRegistry(relyBeanMaps,clazz);
    }
    default <T> T getAdaptive(Injector injector,final Map<String,SafeObjectHolder> relyBeanMaps,Class<T> clazz){
        return injector.getAdaptive(relyBeanMaps,clazz);
    }
    void injectBean(Injector injector,final Map<String,SafeObjectHolder> relyBeanMaps);
}
